package LABS.lab4;

/**************************************************************
* Class PezCandy
* @author Jeff Thomas - Thomas007
* @vesion 1.0.0
* Date: 02.26.2008
* Copyright 2008, Jeff Thomas
***************************************************************/

import java.util.*;

public class PezCandy
{
	private final int NUM_PEZ = 15;
	private int num_orange = 0;
	private Stack<String> pezStack = new Stack<String>();
	private Stack<String> pezStackCopy = new Stack<String>();
/**************************************************************
* Pez Candy
* Task:	1. Constructor for PezCandy that creates the stack
* Side Effects: None
***************************************************************/
	public PezCandy()
	{
		createStack();
	}
/**************************************************************
* Create Stack
* Task:	1. Create a stack of random Pez Colors
*			2. Assign those colors to two Stacks
* Side Effects: None
***************************************************************/
	private void createStack()
	{
		for (int i = 0; i < NUM_PEZ; i++)
		{
			String random = randomColor();
			pezStack.push(random);
			pezStackCopy.push(random);
		}
	}
/**************************************************************
* Random Color
* @return - String of a random Pez color
* Task:	1. Using an array of Pez colors, return a random one
* Side Effects: None
***************************************************************/	
	private String randomColor()
	{
		String[] colors = {"Red", "Blue", "Green", "Yellow", "Orange"};
		int random = (int) (Math.random() * 5);
		return colors[random];
	}
/**************************************************************
* Simulate Brother
* Task:	1. Simulate the brother taking all the orange colors
*			2. Increment the counter for every orange taken.
*			3. Push all to other colors to a new stack
*			4. Reverse the new stack
* Side Effects: None
***************************************************************/
	public void simBrother()
	{
		String color = "";
		while (!pezStackCopy.empty())
		{
			color = pezStackCopy.pop();
			if (color == "Orange")
				num_orange++;
			else
			{
				pezStack.push(color);
			}
		}
		reverseStack();
	}
/**************************************************************
* Get Number of Oranges
* @return - Number of oranges taken from stack
* Side Effects: None
***************************************************************/	
	public int getNumOrange()
	{
		return num_orange;
	}
/**************************************************************
* Reverse Stack
* Task:	1. Reverse the copy stack
* Side Effects: None
***************************************************************/
	private void reverseStack()
	{
		while (!pezStack.empty())
		{
			pezStackCopy.push(pezStack.pop());
		}
	}
/**************************************************************
* Display Stack
* @return - String of colors seperated by "\n" new line
* Task:	1. Add each color from the stack to a StringBuilder
*			2. Seperate each color with a "\n"
* Side Effects: None
***************************************************************/
	public String displayStack()
	{
		StringBuilder result = new StringBuilder();
   	while (!pezStack.empty()) 
		{
  			result.append(pezStack.pop());
			result.append("\n");
   	}
   	return result.toString();
	}
/**************************************************************
* Display Stack Copy
* @return - String of colors seperated by "\n" new line
* Task:	1. Add each color from the stack to a StringBuilder
*			2. Seperate each color with a "\n"
* Side Effects: None
***************************************************************/
	public String displayStackCopy()
	{
		StringBuilder result = new StringBuilder();
   	while (!pezStackCopy.empty()) 
		{
  			result.append(pezStackCopy.pop());
			result.append("\n");
   	}
   	return result.toString();
	}	
}
/**************************************************************
* I, Jeff Thomas, certify that each part of this program was
* written by me, except as noted within the code.
*
*						_________________________
***************************************************************/